<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      table {
        width: 50%;
        border: 1px solid black;
      }
      td,
      th {
        border: 1px solid black;
        text-align: center;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <table>
        <tr class="header">
          <th colspan="3">欢迎光临 vue开发的收银系统_水果店</th>
        </tr>
        <tr>
          <th colspan="3">苹果 10￥/斤, 折扣<8折></th>
        </tr>
        <tr>
          <td colspan="3">
            请输入你要购买的斤数:
            <input type="text" v-model="sum" :value="sum" />
          </td>
        </tr>
        <tr>
          <td colspan="3">
            <button @click="payup()" class="submit">结账买单~</button>
          </td>
        </tr>
        <tr>
          <td colspan="3">
            结账单: 总价: {{total}}￥ 折后价: {{ discount }}￥ 省: {{save}}￥
          </td>
        </tr>
      </table>
    </div>

    <script src="./vue.js"></script>
    <script>
      const app = new Vue({
        el: "#app",
        data: {
          sum: 1,
          total: 10,
          discount: 8,
          save: 2,
        },
        methods: {
          payup() {
            console.log("点击了");

            this.total = parseFloat(this.total) * this.sum;
            this.discount = parseFloat(this.total) * 0.8;
            this.save = parseFloat(this.total) - this.discount;
            this.sum = 0;
            console.log(this.sum);
          },
        },
      });
    </script>
  </body>
</html>
